import request from '../utils/request';

/**
 * 创建应用
 * @param {string} name 应用名
 * @param {number} organizationIdList 组织id列表
 * @param {string} appId 小程序appId
 * @param {string} appSecret 小程序appSecret
 * @param {object} setting 升级参数
 * @param {boolean} active 是否可用
 */
export function createApplicationApi(name, organizationIdList, appId, appSecret, setting, active) {
  return request({
    url: '/applications',
    method: 'post',
    data: {
      name,
      organization_id_list: organizationIdList,
      app_id: appId,
      app_secret: appSecret,
      setting,
      active
    }
  });
}

/**
 * 删除应用
 * @param {string} uuid 应用uuid
 */
export function deleteApplicationApi(uuid) {
  return request({
    url: '/applications/' + uuid,
    method: 'delete'
  });
}

/**
 * 更新应用
 * @param {string} uuid 应用uuid
 * @param {string} name 应用名
 * @param {number} organizationIdList 组织id列表
 * @param {object} setting 升级参数
 * @param {boolean} active 是否可用
 */
export function updateApplicationApi(uuid, name, organizationIdList, setting, active) {
  return request({
    url: '/applications/' + uuid,
    method: 'put',
    data: {
      name,
      organization_id_list: organizationIdList,
      setting,
      active
    }
  });
}

/**
 * 获取应用列表
 * @param {number} pageIndex 分页页码
 * @param {number} pageSize 分页每页数量
 * @param {string} sortType 排列顺序
 * @param {string} name 应用名（支持模糊搜索）
 */
export function getApplicationListApi(pageIndex, pageSize, sortType, name) {
  return request({
    url: '/applications',
    method: 'get',
    params: {
      page_index: pageIndex,
      page_size: pageSize,
      sort_type: sortType,
      name
    }
  });
}
